/*
 *  $Id: Eating.cs 975 2009-12-16 17:13:22Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: поедание
    /// Значение: макс.здоровье поедаемого существа
    /// Если вражеское существо имеет здоровье X и ниже, то вместо нанесения урона оно поедается.
    /// </summary>
    public class Eating: Affect {
        public static readonly Languages.Phrase Action = new Languages.Phrase("affect.eating.action");

        private int _value;
        private Predicate<Creature> _condition;

        public Eating(int value, Predicate<Creature> condition) {
            _value = value;
            _condition = condition;
        }

        public override string Id {
            get { return "eating"; }
        }
        public override string NameText {
            get { return Name.GetText(_value); }
        }

        public override int BaseWeight {
            get { return _value * 15; }
        }

        public override AffectIcon Icon {
            get { return AffectIcon.Eating; }
        }

        public override Affect Clone() {
            return new Eating(_value, _condition);
        }

        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.Eating.Add(this);
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.Eating.Remove(this);
        }

        public bool CanEat(Creature victim) {
            if (_condition != null && !_condition(victim)) return false;
            return _value >= victim.Health;
        }
    }
}